package com.free.semantic.infrastruct.mapper;

import com.free.semantic.infrastruct.common.UserSemanticNetworkDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserSemanticNetworkMapper {
    
    @Insert("INSERT INTO user_semantic_network (user_id, semantic_network_id, permission, create_time, update_time) " +
            "VALUES (#{userId}, #{semanticNetworkId}, #{permission}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(UserSemanticNetworkDO userSemanticNetworkDO);

    @Delete("DELETE FROM user_semantic_network WHERE id = #{id}")
    int deleteById(Long id);

    @Select("SELECT * FROM user_semantic_network WHERE id = #{id}")
    UserSemanticNetworkDO findById(Long id);

    @Select("SELECT * FROM user_semantic_network WHERE user_id = #{userId}")
    List<UserSemanticNetworkDO> findByUserId(Long userId);

    @Select("SELECT * FROM user_semantic_network WHERE semantic_network_id = #{semanticNetworkId}")
    List<UserSemanticNetworkDO> findBySemanticNetworkId(Long semanticNetworkId);

    @Select("SELECT * FROM user_semantic_network WHERE user_id = #{userId} AND semantic_network_id = #{semanticNetworkId}")
    UserSemanticNetworkDO findByUserIdAndSemanticNetworkId(@Param("userId") Long userId, @Param("semanticNetworkId") Long semanticNetworkId);

    @Update("UPDATE user_semantic_network SET permission = #{permission}, update_time = #{updateTime} " +
            "WHERE id = #{id}")
    int updatePermission(UserSemanticNetworkDO userSemanticNetworkDO);
} 